using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Microsoft.Phone.Controls.Primitives
{
	public class PanningTitleLayer : PanningLayer
	{
		private double WidthAdjustment
		{
			get
			{
				return (double)base.Owner.ViewportWidth * 0.625;
			}
		}
		protected override double PanRate
		{
			get
			{
				double result = 1.0;
				if (base.Owner != null && base.ContentPresenter != null)
				{
					result = (Math.Max((double)base.Owner.ViewportWidth, base.ContentPresenter.get_ActualWidth() + this.WidthAdjustment) - (double)(base.Owner.ViewportWidth / 5 * 4)) / (double)Math.Max(base.Owner.ViewportWidth, base.Owner.ItemsWidth);
				}
				return result;
			}
		}
		public override void Wraparound(int direction)
		{
			if (direction < 0)
			{
				int targetOffset = (int)((base.ActualOffset + base.ContentPresenter.get_ActualWidth() + this.WidthAdjustment) / this.PanRate);
				base.GoTo(targetOffset, PanningLayer.Immediately, null);
				return;
			}
			int targetOffset2 = (int)((base.ActualOffset - base.ContentPresenter.get_ActualWidth() - this.WidthAdjustment) / this.PanRate);
			base.GoTo(targetOffset2, PanningLayer.Immediately, null);
		}
		protected override void UpdateWrappingRectangles()
		{
			PerfLog.BeginLogMarker(PerfMarkerEvents.MPC_PANO_UPDATEWRAPPING, PerfLog.PanningLayer);
			ItemsPresenter itemsPresenter = base.get_Content() as ItemsPresenter;
			bool flag = itemsPresenter == null || base.Owner.Panel == null || base.Owner.Panel.VisibleChildren.get_Count() < 3;
			base.RightWraparound.set_Visibility((base.IsStatic || !flag) ? 1 : 0);
			if (!base.IsStatic && flag)
			{
				base.RightWraparound.set_Height(base.ContentPresenter.get_ActualHeight());
				base.RightWraparound.set_Width((double)base.Owner.ViewportWidth);
				WriteableBitmap writeableBitmap = new WriteableBitmap(base.Owner.ViewportWidth, (int)base.ContentPresenter.get_ActualHeight());
				TranslateTransform translateTransform = new TranslateTransform();
				writeableBitmap.Render(base.ContentPresenter, translateTransform);
				writeableBitmap.Invalidate();
				Shape arg_E9_0 = base.RightWraparound;
				ImageBrush imageBrush = new ImageBrush();
				imageBrush.set_ImageSource(writeableBitmap);
				arg_E9_0.set_Fill(imageBrush);
			}
			int num = (int)((double)base.Owner.ViewportWidth * 0.1);
			base.RightWraparound.set_Margin(new Thickness(this.WidthAdjustment + (double)num, 0.0, 0.0, 0.0));
			PerfLog.EndLogMarker(PerfMarkerEvents.MPC_PANO_UPDATEWRAPPING, PerfLog.PanningLayer);
		}
	}
}
